package com.himore.api.web.service.impl;


import com.himore.api.common.core.text.Convert;
import com.himore.api.common.utils.CommonUtils;
import com.himore.api.common.utils.DateUtils;
import com.himore.api.common.utils.StringUtils;
import com.himore.api.web.mapper.TCommentPictureMapper;
import com.himore.api.web.mapper.TSysCommentMapper;
import com.himore.api.web.mapper.TSysInvitationMapper;
import com.himore.api.web.mapper.TSysLikeMapper;
import com.himore.api.web.model.*;
import com.himore.api.web.service.ITSysInvitationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 帖子Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-05-13
 */
@Service
public class TSysInvitationServiceImpl implements ITSysInvitationService
{
    @Autowired
    private TSysInvitationMapper tSysInvitationMapper;


    @Autowired
    private TCommentPictureServiceImpl tCommentPictureService;


    @Autowired
    private TSysLikeMapper tSysLikeMapper;

    @Autowired
    private TSysCommentMapper tSysCommentMapper;


    /**
     * 查询帖子
     * 
     * @param invitationId 帖子ID
     * @return 帖子
     */
    @Override
    public TSysInvitation selectTSysInvitationById(Long invitationId)
    {
        return tSysInvitationMapper.selectTSysInvitationById(invitationId);
    }

    /**
     * 查询帖子列表
     *
     * @param tSysInvitation 帖子
     * @return 帖子
     */
    @Override
    public List<InvitationVO> selectTSysInvitationList(TSysInvitation tSysInvitation)
    {
        return tSysInvitationMapper.selectTSysInvitationList(tSysInvitation);
    }

    @Override
    public List<TSysInvitation> selectTSysInvitationList1(TSysInvitation tSysInvitation) {
        return tSysInvitationMapper.selectTSysInvitationList1(tSysInvitation);
    }

    /**
     * 新增帖子
     * 
     * @param tSysInvitation 帖子
     * @return 结果
     */
    @Override
    public int insertTSysInvitation(TSysInvitation tSysInvitation)
    {
        String inviteId = CommonUtils.generateCodeKey();
        tSysInvitation.setInvitationId(inviteId);
        if(StringUtils.isListNotNull(tSysInvitation.getPicList())){
            List<HashMap>  picList=tSysInvitation.getPicList();
            if(null!= picList && picList.size()>0){
                for(HashMap<String,String> pic :picList){
                    TCommentPicture temp = new TCommentPicture();
                    temp.setPicPath(pic.get("picPath"));
                    temp.setPicRealPath(pic.get("realPath"));
                    temp.setInvitationId(inviteId);
                    temp.setCreateTime(DateUtils.getNowDate());
                    tCommentPictureService.insertTCommentPicture(temp);
                }
            }
        }
        tSysInvitation.setCreateTime(DateUtils.getNowDate());
        return tSysInvitationMapper.insertTSysInvitation(tSysInvitation);
    }

    /**
     * 修改帖子
     * 
     * @param tSysInvitation 帖子
     * @return 结果
     */
    @Override
    public int updateTSysInvitation(TSysInvitation tSysInvitation)
    {
        tSysInvitation.setUpdateTime(DateUtils.getNowDate());
        return tSysInvitationMapper.updateTSysInvitation(tSysInvitation);
    }

    /**
     * 删除帖子对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTSysInvitationByIds(String ids)
    {
        return tSysInvitationMapper.deleteTSysInvitationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除帖子信息
     * 
     * @param invitationId 帖子ID
     * @return 结果
     */
    @Override
    public int deleteTSysInvitationById(Long invitationId)
    {
        return tSysInvitationMapper.deleteTSysInvitationById(invitationId);
    }

    @Override
    public int updateCommentCount(TSysInvitation tSysInvitation) {
        return tSysInvitationMapper.updateCommentCount(tSysInvitation);
    }


    /**
     * 查询我的帖子列表
     *
     * @param tSysInvitation 帖子
     * @return 帖子
     */
    @Override
    public List<InvitationVO> selectMyInvitationList(TSysInvitation tSysInvitation)
    {
        return tSysInvitationMapper.selectMyInvitationList(tSysInvitation);
    }

    /**
     * 查询通知列表
     *
     * @param param 参数
     * @return 帖子集合
     */
    public List<SysNoticeVO> selectNoticeInfo(Map param){
        return tSysInvitationMapper.selectNoticeInfo(param);
    }


    @Override
    public int selectNoticeCount(HashMap param) {
        return tSysInvitationMapper.selectNoticeCount(param);
    }


    @Override
    public void updateNoticeStatus(HashMap param) {
        tSysLikeMapper.updateReadStatus(param);
        tSysCommentMapper.updateReadStatus(param);
    }


    @Override
    public List<InvitationVO> selectNewInvitationList(TSysInvitation tSysInvitation) {
        return tSysInvitationMapper.selectNewInvitationList(tSysInvitation);
    }

    @Override
    public List<InvitationVO> selectNextPageList(TSysInvitation tSysInvitation) {
        return tSysInvitationMapper.selectNextPageList(tSysInvitation);
    }
}
